package com.gu.controller;

import com.github.pagehelper.PageInfo;
import com.gu.VO.LayuiVO;
import com.gu.VO.PropertyVO;
import com.gu.VO.ServerResponse;
import com.gu.entity.ApartmentDO;
import com.gu.entity.PropertyDO;
import com.gu.service.ApartmentService;
import com.gu.service.PropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ProjectName: apartment-management-center
 * @Package: com.gu.controller
 * @ClassName: PropertyController
 * @Author: gusongliao
 * @Description: 物业维修控制器
 * @createDate 2021/04/13 13:54
 */
@Controller
@RequestMapping("/property")
public class PropertyController {

    @Autowired
    private PropertyService propertyService;

    @Autowired
    private ApartmentService apartmentService;

    @RequestMapping("/propertyList")
    @ResponseBody
    public LayuiVO propertyList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, String selectUserParam, Integer id,Integer repairStatus){
        PageInfo propertyList = propertyService.propertyList(pageNum,pageSize,selectUserParam,id,repairStatus);
        return LayuiVO.success(propertyList.getTotal(),propertyList.getList());
    }

    @RequestMapping("/propertyListNew")
    @ResponseBody
    public LayuiVO propertyListNew(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,Integer repairStatus){
        PageInfo propertyList = propertyService.propertyListNew(pageNum,pageSize,repairStatus);
        return LayuiVO.success(propertyList.getTotal(),propertyList.getList());
    }

    @RequestMapping("/propertyListByUserId")
    @ResponseBody
    public LayuiVO propertyListByUserId(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize,Integer ownerId,Integer repairStatus){
        PageInfo propertyList = propertyService.propertyListByUserId(pageNum, pageSize, ownerId, repairStatus);
        return LayuiVO.success(propertyList.getTotal(),propertyList.getList());
    }


    /**
     * @Description //更新用户状态
     * @User 谷松辽
     * @Date 2021/3/7 15:08
     * @return com.gu.VO.ServerResponse
     */
    @PostMapping("/updateRepairStatus")
    @ResponseBody
    public ServerResponse updateRepairStatus(@RequestBody PropertyDO propertyDO){
        return propertyService.updateRepairStatus(propertyDO);
    }

    @PostMapping("/insertProperty")
    @ResponseBody
    public ServerResponse insertProperty(@RequestBody PropertyDO propertyDO){
        return propertyService.insert(propertyDO);
    }

    @GetMapping("/deleteProperty")
    @ResponseBody
    public ServerResponse deleteByIds(Integer[] id) {
        return propertyService.deleteByIds(id);
    }

    @GetMapping("/jumpPropertyUser")
    public String jumpPropertyUser(Integer userId, ModelMap modelMap) {
        List<PropertyVO> propertyVOS = apartmentService.getApartmentByUser(userId);
        modelMap.addAttribute("apartmentNameList",propertyVOS);
        return "propertyUser";
    }

}
